@extends('admin.base')
@section('title', '管理员列表')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/admin/index')}}"
                   style="cursor:pointer;"><cite>管理员列表</cite></a>;
            </span>
            </div>
        </fieldset>
        <div class="layui-card-header">
            <div>
        <span class="pull-left">
          <div class="layui-form">
            <div class="layui-form-item">
              <div class="layui-inline">     
                <label class="layui-form-label">关键字</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="sub_keywords" name="keywords"
                           value="{{ isset($keywords) ? $keywords : '' }}" placeholder="账号">
                </div>
                
                <label class="layui-form-label">时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" class="jeinput" id="test11" placeholder="创建时间(年月日~年月日)"
                           name="month" value="{{ isset($month) ? $month : '' }}" readonly>
                </div>
                <div class="layui-input-inline">
                  <button class="layui-btn" lay-submit lay-filter="selectsub">搜索</button>
                    <!-- <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="exportsub" ></i>导出</button>  -->
                </div>
              </div>
            </div>
          </div>
        </span>

                <span class="pull-right">
            <button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/admin/add')}}','','添加');">
                <i class="layui-icon">&#xe608;</i> 添加
            </button>
        </span>
            </div>
        </div>

        <div class="layui-card-body">
            <style>
                table tr td.tc, table tr th.tc {
                    text-align: center;
                    cursor: default;
                }
            </style>
            <table class="layui-table" lay-even lay-size="">
                <colgroup>
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                </colgroup>

                <thead>
                <tr>
                    <th class="tc">ID</th>
                    <th class="tc">账号</th>
                    <th class="tc">角色</th>
                    <th class="tc">状态</th>
                    <th class="tc">创建时间</th>
                    <th class="tc">操作</th>
                </tr>
                <tbody>
                @if($list->isEmpty())
                    <tr>
                        <td colspan="6" class="tc">暂无数据</td>
                    </tr>
                @else
                    @foreach ($list as $v)
                        <tr>
                            <td class="tc">{{ $v['id'] }}</td>
                            <td class="tc">{{ $v['user'] }}</td>
                            <td class="tc">
                                @if($v['id']==1)
                                    总管理员
                                @endif
                                @foreach ($v->roles as $role)
                                    <button class="layui-btn layui-btn-sm layui-btn-primary">{{$role['name']}}</button>
                                @endforeach
                            </td>
                            <td class="tc">
                                <form class="layui-form " action="">
                                    <input type="checkbox" @if($v['state']['value']==1) checked @endif name=""
                                           lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用"
                                           value="{{ $v['id'] }}"
                                           @if($v['id']==1 || $v['id'] == $session_id) disabled @endif>
                                </form>
                            </td>
                            <td class="tc">{{$v['created_at']}}</td>
                            <td class="tc">
                                <div class="layui-btn-group">
                                    @if($v['id'] == $session_id)
                                        <button class="layui-btn layui-btn-sm"
                                                onclick="active('{{url('admin/admin/personal')}}','{{$v['id']}}','个人资料');">
                                            个人资料
                                        </button>
                                    @else
                                        @if($v['id'] != 1)
                                            <button class="layui-btn layui-btn-sm"
                                                    onclick="active('{{url('admin/admin/edit')}}','{{$v['id']}}','编辑');">
                                                编辑
                                            </button>
                                            <button class="layui-btn layui-btn-sm layui-btn-danger"
                                                    onclick="del('{{url('admin/admin/del')}}','{{$v['id']}}');">删除
                                            </button>
                                        @endif
                                    @endif

                                </div>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                </thead>
            </table>
            <!-- 分页 -->
            <div class="sabrosus">{{ $page }}</div>
        <!-- {{$list->total()}} -->
        </div>

    </div>
@endsection
@section('js')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function (data) {
                let keywords = $('#sub_keywords').val();//关键字
                let month = $("#test11").val();//时间
                // let level = $("#level option:selected").val();//级别
                // layer.msg(keywords+"|"+month+"|"+level)
                location.href = "{{url('admin/admin/index')}}" + "?keywords=" + keywords + "&month=" + month;
                return false;
            });

            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                var id = data.value;

                if (data.elem.checked) {
                    var state = 1;//启用
                } else {
                    var state = 0;//禁用               
                }
                ajax('/admin/admin/up_state', {id: id, state: state});
            });
        });
    </script>
@endsection